package tech.yangzhijie.basic.java05;

public class Java05 {
    public static void main(String[] args) {
        Student[] students = new Student[10];
        for (int i = 0; i < 10; i++) {
            students[i] = new Student("小明"+i,(int)(Math.random()*100000)+1+"",(int)(Math.random()*10)==1?"男":"女",(int)(Math.random()*100)+1,(int)(Math.random()*100)+1,(int)(Math.random()*100)+1);
        }

        for(int i=0;i<students.length-1;i++){
            for (int j = 0; j < students.length - 1 - i; j++) {
                if(students[j].compareTo(students[j+1])==-1){
                    Student student = students[j];
                    students[j] = students[j+1];
                    students[j+1] = student;
                }
            }
        }

        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i]);
        }
    }
}

class Student implements Comparable<Student>{
    private String name;
    private String studentID;
    private String sex;
    private Integer chinese;
    private Integer math;
    private Integer english;

    public Student(String name, String studentID, String sex, Integer chinese, Integer math, Integer english) {
        this.name = name;
        this.studentID = studentID;
        this.sex = sex;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }

    public Student() {
    }

    @Override
    public int compareTo(Student s) {
        return Integer.compare(this.theAverageScore(),s.theAverageScore());
    }

    public int theAverageScore(){
        return (this.chinese+this.math+this.english)/3;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", studentID='" + studentID + '\'' +
                ", sex='" + sex + '\'' +
                ", chinese=" + chinese +
                ", math=" + math +
                ", english=" + english +
                ", theAverageScore="+this.theAverageScore()+"}";
    }
}
